﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.SqlClient;
using jiaju.Models;
using jiaju.Models.DBModel;
using jiaju.Models.DAL;
namespace jiaju.Controllers
{
    public class ProductController : Controller
    {
        //案例展示
        // GET: Product
        public ActionResult Index(string Id, string TypeName)
        {
            List<ProductType> list = ProductTypeService.GetProductType();
            ViewBag.A = list;

            if (string.IsNullOrEmpty(Id))
            {
                ViewBag.C = "全部商品";
            }
            else
            {
                ViewBag.C = Id;
                ViewBag.D = TypeName;
            }
            return View();
        }
        public ActionResult DelPage(int page, int limit, string TypeId, string name)
        {
            string sql = "select count(*) from  dbo.Product";
            if (!String.IsNullOrEmpty(name))
            {
                sql = sql + " where name like '%" + name + "%'";
            }
            int count = (int)DBHelp.ExcuteScalar(sql);
            List<Product> product = new List<Product>();
            if (TypeId == "全部商品")
            {
                product = ProductService.GetAllProduct(page, limit, name);
            }
            else
            {
                product = ProductService.GetTypeProduct(page, limit, TypeId, name);
                sql = sql + " where ProductTypeId=" + TypeId;
            }

            return Json(new { success = true, count = count, data = product });


        }
    }
}
